exports.SwingAnimation = UI.View.subclass(
{
    classname: 'SwingAnimation',
    
    initialize: function(direction)
    {
		this._pointerImage = null;
		this._duration = 75;//in milli secs
		this._offset = 0;
		this._direction = direction;
		this._animateCount = 0;
		this.animateTimeout = null;
    },
	
	createView: function() 
	{
		this.loadView();
		this._animate();
	},  
	
	setPosition: function(position)
	{
		if(position)
		{
			this.setFrame([position[0] ,position[1], TCUtil.getAdjustedX(90), TCUtil.getAdjustedY(50)]);
		}
	},
	
	loadView: function()
	{
		var imagePath = null;
		if(this._direction == kSwingDirection.kSwingDirectionRight)
		{
			imagePath = this.getBaseResourcePath()+'arrowright.png';
		}
		else 
		{
			imagePath = this.getBaseResourcePath()+'arrowleft.png';
		}		
		this._pointerImage = UIFactory.getImage([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(75),TCUtil.getAdjustedY(40)],imagePath);
		this.addChild(this._pointerImage);
	},
	
	_animate: function()
	{
		if(this.animateTimeout)
		{
			clearTimeout(this.animateTimeout);
			this._animateCount = 0;
		}
		this._offset = 0;		
		this.animateTimeout = setInterval(this._animateRight.bind(this), this._duration)
	},
	
	_animateRight: function()
	{
		this._pointerImage.setFrame([TCUtil.getAdjustedX(0 + this._offset),TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(75),TCUtil.getAdjustedY(40)]);
		this._offset += 3;
		this._animateCount += 1;	

		if(this._animateCount > 5)
		{
			this.animateRightDoneCB();
		}	
	},
	
	animateRightDoneCB: function()
	{
		if(this.animateTimeout)
		{
			clearTimeout(this.animateTimeout);
			this.animateTimeout = null;
		}
		this._animateCount = 0;
		this.animateTimeout = setInterval(this._animateLeft.bind(this), this._duration)	
	},
	
	_animateLeft: function()
	{
		this._pointerImage.setFrame([TCUtil.getAdjustedX(this._offset),TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(75),TCUtil.getAdjustedY(40)]);
		this._offset -= 3;
		this._animateCount += 1;	
		if(this._animateCount > 5)
		{
			this._animate();
		}	
	},

	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/tutorial/";
	},
	
	destroy: function ()
	{
		if(this._pointerImage)
		{
			this._pointerImage.destroy();
			this._pointerImage = null;
		}
		if(this.animateTimeout)
		{
			clearTimeout(this.animateTimeout);
			this.animateTimeout = null;
		}

	}
});